package com.woniuxy.exam.controller;

import com.woniuxy.commons.entity.Label;
import com.woniuxy.commons.entity.ResponseEntity;
import com.woniuxy.exam.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zouyang
 * @date 2020/7/18 - 10:23
 */
@RestController
@RequestMapping("/label")
public class LabelController {
    @Autowired
    private LabelService labelService;

    @GetMapping("/all")
    public List<Label> getAll(){
        return labelService.selectAll();
    }

    @PostMapping("/search")
    public List<Label> search(Label label){
        return labelService.selectByAll(label);
    }

    @RequestMapping("/add")
    private ResponseEntity addLabel(Label label){
        int res = labelService.insert(label);
        if (res==1){
            return ResponseEntity.SUCCESS_RESPONSE;
        }
        return new ResponseEntity(500,"出现异常");
    }

    @RequestMapping("/update")
    private ResponseEntity updateLabel(Label label){
        int res = labelService.updateByPrimaryKey(label);
        if (res==1){
            return ResponseEntity.SUCCESS_RESPONSE;
        }
        return new ResponseEntity(500,"出现异常");
    }

    @RequestMapping("/del")
    private ResponseEntity deleteQuestionBank(Label label){
        int res = labelService.deleteByPrimaryKey(label.getId());
        if (res==1){
            return ResponseEntity.SUCCESS_RESPONSE;
        }
        return new ResponseEntity(500,"出现异常");
    }
}
